package com.naicheng.ivote.utils;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

public class TimeUtil {

	public static String getFormatTime(long time) {

		long currentTime = System.currentTimeMillis();
		long mil = (currentTime - time)/1000;
		
		
		System.out.println("time================"+time);
		System.out.println("currentTime================="+currentTime);
		System.out.println("mil================"+mil);
		
		
		if (mil < 0) {
			return "刚刚";
		}

		else if (mil > 0 && mil < 60) {
			return mil + "秒钟前";
		}

		else if (mil > 60 && mil < 3600) {
			return mil / 60 + "分钟前";
		}

		else if (mil > 3600 && mil < 86400) {
			return mil / 3600 + "小时前";
		}

		else if (mil > 86400 && mil < 604800) {// 小于一周
			return mil / 86400 + "天前";// 3天以内显示
		}

		else if (mil > 604800 && mil < 2592000) {// 小于一月
			return mil / 604800 + "周前";
		}

		else if (mil > 2592000 && mil < 7776000) {// 小于三个月
			return mil / 2592000 + "个月前";
		}

		else {
			return "";
		}

	}
	public static String getOrderDate(long time){
		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		Date nowDate = new Date(time);
		String currDate = df.format(nowDate);
		return currDate;
	}
	public static String getScoreDate(long time){
		SimpleDateFormat df = new SimpleDateFormat("MM月dd日 HH:mm");
		Date nowDate = new Date(time);
		String currDate = df.format(nowDate);
		return currDate;
	}
	public static String getOrderEndDate(long time){
		SimpleDateFormat df = new SimpleDateFormat("yyyy年MM月dd日 HH:mm:ss");
		Date nowDate = new Date(time);
		String currDate = df.format(nowDate);
		return currDate;
	}
	public static String date2string(Date date){
		SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmmss");
		return format.format(date);
	}

}
